package logic

import (
	"3kz/zk3rpc/zk3rpc"
	"context"

	"3kz/api/internal/svc"
	"3kz/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddLogic {
	return &AddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AddLogic) Add(req *types.AddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	Add, err := l.svcCtx.Zk3Rpc.Add(l.ctx, &zk3rpc.AddRequest{
		ProductCode:  req.ProductCode,
		ProductName:  req.ProductName,
		ProductPrice: req.ProductPrice,
		ProductCost:  req.ProductCost,
		Img:          req.Img,
		UserId:       int64(req.UserId),
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    "500",
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "添加成功",
		Code:    "200",
		Data:    Add,
	}, nil

}
